//
//  DownLoadManager.m
//  lisure0.1
//
//  Created by xalo on 16/4/25.
//  Copyright © 2016年 Mr.wangYongxu. All rights reserved.
//

#import "DownLoadManager.h"
#import "DownLoadTool.h"
#import "PlayInfoModel.h"

@interface DownLoadManager ()<DownLoadToolDelegate>



@end

@implementation DownLoadManager

-(NSMutableDictionary *)downloadList{

    if (!_downloadList) {
        _downloadList = [NSMutableDictionary dictionary];
    }
    return _downloadList;
}

+(instancetype)defaultManager{

    static DownLoadManager* manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[DownLoadManager alloc] init];
    });
    return manager;
}

//添加down
-(DownLoadTool *)addDownLoadWithPlayInfoModel:(PlayInfoModel*)model{

    DownLoadTool* downLoad = [self.downloadList objectForKey:model.musicUrl];
    if (!downLoad) {
        downLoad = [[DownLoadTool alloc] initWithMoldel:model];
        downLoad.delegate = self;
        [downLoad startDownLoad];
        [self.downloadList setValue:downLoad forKey:model.musicUrl];
    }
    NSLog(@"%@",self.downloadList);
    return downLoad;
}

//根据url找到一个download
-(DownLoadTool*)downLoadWithmodel:(PlayInfoModel* )model{

    DownLoadTool* downLoad = [self.downloadList objectForKey:model.musicUrl];
    return downLoad;
}

-(void)downLoadidiFinishedmodel:(PlayInfoModel *)model{

    [self.downloadList removeObjectForKey:model.musicUrl];
    NSLog(@"完成");
}

@end
